<template>
	<view class="hui">
		<u-navbar leftIconColor="black" :autoBack="true" title="填写订单" titleStyle="color:black" :placeholder="true"
			bgColor="#fff">
		</u-navbar>
		<view class="list_box">
			<view class="info_box b_m_bs">
				<view class="b_flex_c o_box">
					<image class="img" :src="info.sliderImage"></image>
					<view class="r_box">
						<view class="b_flex_c_s b_m_bs">
							<view class=" name">{{info.name}}</view>

						</view>
						<view class="b_flex_c_s">
							<view class="price">￥{{info.price}}/{{info.unit}}</view>
							<view>
								<u-number-box  v-model="form.num" @change='sum'></u-number-box>
							</view>
						</view>
					</view>
				</view>
				<view class="b_flex_c_s yu_box i_box">
					<view>所属医院</view>
					<view>{{info.hospitalName}}</view>
				</view>
			</view>
			<view class="info_box b_m_bs">
				<view class="title mb">取货人信息</view>
				<view class="b_flex_c_s i_box mb">
					<view>电话</view>
					<view>{{user.phone}}</view>
				</view>
				<view class="b_flex_c_s i_box">
					<view>租用天数</view>
					<view>
						<u-number-box :disabled="true" :min="2" v-model="form.days" @change='sums'></u-number-box>
					</view>
				</view>
			</view>
			<view class="info_box">
				<view class="b_flex_c_s i_box mb">
					<view>租赁金额</view>
					<view class="b_f_w">￥{{price}}</view>
				</view>
				<view class="b_flex_c_s i_box mb">
					<view>租赁押金</view>
					<view class="b_orange b_f_w">￥{{yj}}</view>
				</view>
				<view class="b_flex_c_s i_box">
					<view>合计</view>
					<view class="b_red b_f_w">￥{{hj}}</view>
				</view>
			</view>
		</view>
		<view class="bottom_box">
			<!-- <u-radio-group v-model="xyCheck" size="15" active-color="#3C7CFF">
				<view class="b_flex_c xy_box">
					<view>
						<u-radio icon-size="15" :name="1"></u-radio>
					</view>
					<view class="yd">我已阅读</view>
					<view class="xy" @click="$project.toPath('/pages/lock/agreement?type=1')">《用户及付款协议》</view>
					<view class="xy" @click="$project.toPath('/pages/lock/agreement?type=2')">《租赁免责协议》</view>
				</view>
			</u-radio-group> -->
			<view class="b_flex_c button_box">
				<view class="he">合计:<span class="money">￥</span>{{hj}}</view>
				<view class="pay" @click="pay">立即支付</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		userInfo,
		quiltOrder
	} from "@/require/api.js";
	export default {
		data() {
			return {
				info: {},
				form: {
					num: 1,
					days: 2,
					quiltId: ''
				},
				user: {},
				xyCheck: '',
				price: '',
				yj: 20,
				deposit:'',
				hj: ''
			}
		},
		onLoad(data) {
			if (data.item) {
				this.info = JSON.parse(decodeURIComponent(data.item));
				this.form.quiltId = this.info.id;
				this.yj=parseInt(this.info.deposit);
				this.deposit=parseInt(this.info.deposit);
				this.sum();
			}
		},
		onShow() {
				
			this.getUserInfo();
		},
		methods: {
			async pay() {
				let {
					data
				} = await quiltOrder(this.form);
				let _ = this;
				uni.requestPayment({
					provider: 'wxpay',
					timeStamp: data.data.jsConfig.timeStamp,
					nonceStr: data.data.jsConfig.nonceStr,
					package: data.data.jsConfig.packages,
					signType: data.data.jsConfig.signType,
					paySign: data.data.jsConfig.paySign,
					success: function(res) {
						_.$project.toast('支付成功');
						setTimeout(() => {
							_.$project.toBack();
						}, 1000);
					},
					fail: function(err) {
						_.$project.toast('支付取消');
					}
				});
			},
			sum(e = '') {
				if (e) {
					e = e.value;
				} else {
					e = this.form.num;
				}
				this.price = this.info.price * e * this.form.days;
				this.yj=this.deposit*e;
				this.hj = this.price + this.yj;
			},
			sums(e = '') {
				if (e) {
					e = e.value;
				} else {
					e = this.form.days;
				}
				this.price = this.info.price * this.form.num * e;
				this.hj = this.price + this.yj;
			},
			async getUserInfo() {

				let {
					data
				} = await userInfo();
				this.user = data;

			},
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .u-navbar__content__title {
		font-size: 32rpx !important;
		font-weight: bold;
		color: #252B50 !important;
	}

	.list_box {
		box-sizing: border-box;
		padding: 20rpx 30rpx;
	}

	.info_box {
		background-color: #fff;
		border-radius: 8rpx;
		box-sizing: border-box;
		padding: 30rpx;
	}

	.o_box {
		margin-top: 20rpx;
	}

	.img {
		width: 140rpx;
		height: 140rpx;
		border-radius: 8rpx;
		margin-right: 20rpx;

	}

	.r_box {
		flex: 1;
	}

	.name {

		font-size: 26rpx;
		font-weight: bold;
		color: #252B50;
	}

	.price {
		font-size: 24rpx;
		font-weight: 500;
		color: #FF0100;
	}

	.qh {
		width: 140rpx;
		height: 32rpx;
		line-height: 32rpx;
		text-align: center;
		border: 1px solid #FB8753;
		border-radius: 6rpx;
		font-size: 18rpx;
		font-weight: 500;
		color: #FB8753;
	}

	.i_box {
		font-size: 28rpx;
		font-weight: 500;
		color: #252B50;

	}

	.title {

		font-size: 30rpx;

		font-weight: bold;
		color: #252B50;


	}

	.mb {
		margin-bottom: 40rpx;
	}

	.bottom_box {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 100%;
		box-sizing: border-box;
		padding: 30rpx;
	}


	.xy_box {
		font-size: 28rpx;
	}

	.yd {
		color: #9296AF;
	}

	.xy {
		color: #3C7CFF;
	}

	.button_box {
		margin-top: 50rpx;
	}

	.he {
		width: 62%;
		height: 90rpx;
		line-height: 90rpx;
		color: #fff;
		background-color: #252B50;
		border-radius: 8rpx 0 0 8rpx;
		box-sizing: border-box;
		padding: 0 0 0 30rpx;
	}

	.pay {
		width: 38%;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		color: #fff;
		background-color: #3C7CFF;
		border-radius: 0 8rpx 8rpx 0;

	}

	.money {
		font-size: 25rpx;
	}
	.yu_box{
		box-sizing: border-box;
		padding: 20rpx 0 0 0; 
	}
</style>